home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / Examples / Movie / Sources / MovieSel.cpp < prev    next >
Encoding:
Text File  |  1995-11-08  |  10.9 KB  |  345 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                MovieSel.cpp
  4. //    Release Version:    $ 1.0d11 $
  5. //
  6. //    Copyright:    © 1993, 1995 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #ifndef MOVIESEL_H
  11. #include "MovieSel.h"
  12. #endif
  13.  
  14. #ifndef MOVIEPAR_H
  15. #include "MoviePar.h"
  16. #endif
  17.  
  18. #ifndef MOVIEFRA_H
  19. #include "MovieFra.h"
  20. #endif
  21.  
  22. #ifndef CMOVIE_H
  23. #include "CMovie.h"
  24. #endif
  25.  
  26. // ----- Framework Includes -----
  27.  
  28. #ifndef FWPRTITE_H
  29. #include "FWPrtIte.h"
  30. #endif
  31.  
  32. #ifndef FWITERS_H
  33. #include "FWIters.h"
  34. #endif
  35.  
  36. #ifndef FWPRESEN_H
  37. #include "FWPResen.h"
  38. #endif
  39.  
  40. // ----- OS Layer -----
  41.  
  42. #ifndef FWMEMMGR_H
  43. #include "FWMemMgr.h"
  44. #endif
  45.  
  46. #ifndef FWFILESP_H
  47. #include "FWFileSp.h"
  48. #endif
  49.  
  50. #ifndef FWSUSINK_H
  51. #include "FWSUSink.h"
  52. #endif
  53.  
  54. // ----- OpenDoc Includes -----
  55.  
  56. #ifndef SOM_ODShape_xh
  57. #include <Shape.xh>
  58. #endif
  59.  
  60. #ifndef _ODSESSM_
  61. #include <ODSessn.xh>
  62. #endif
  63.  
  64. #ifndef SOM_Module_OpenDoc_StdProps_defined
  65. #include <StdProps.xh>
  66. #endif
  67.  
  68. #ifndef SOM_Module_OpenDoc_StdTypes_defined
  69. #include <StdTypes.xh>
  70. #endif
  71.  
  72. #ifndef SOM_ODTransform_xh
  73. #include <Trnsform.xh>
  74. #endif
  75.  
  76. #ifndef SOM_ODStorageUnit_xh
  77. #include <StorageU.xh>
  78. #endif
  79.  
  80. #ifndef SOM_ODTranslation_xh
  81. #include <Translt.xh>
  82. #endif
  83.  
  84. // ----- Macintosh Includes -----
  85.  
  86. #if defined(FW_BUILD_MAC) && !defined(__DRAG__)
  87. #include <Drag.h>
  88. #endif
  89.  
  90. //========================================================================================
  91. //    Runtime informations
  92. //========================================================================================
  93.  
  94. #ifdef FW_BUILD_MAC
  95. #pragma segment odfmovie
  96. #endif
  97.  
  98. //========================================================================================
  99. //    class CMovieSelection
  100. //========================================================================================
  101.  
  102. //---------------------------------------------------------------------------------------
  103. //    CMovieSelection::CMovieSelection
  104. //---------------------------------------------------------------------------------------
  105.  
  106. CMovieSelection::CMovieSelection(Environment* ev, CMoviePart* moviePart) :
  107.     FW_CSelection(ev, FALSE, FALSE),
  108.     fMoviePart(moviePart)
  109. {
  110. }
  111.  
  112. //---------------------------------------------------------------------------------------
  113. //    CMovieSelection::~CMovieSelection
  114. //---------------------------------------------------------------------------------------
  115.  
  116. CMovieSelection::~CMovieSelection()
  117. {
  118. }
  119.  
  120. //---------------------------------------------------------------------------------------
  121. //    CMovieSelection::CloseSelection
  122. //---------------------------------------------------------------------------------------
  123.  
  124. void CMovieSelection::CloseSelection(Environment* ev)
  125. {
  126.     FW_CPresentationFrameIterator iter(GetPresentation(ev));
  127.     for (CMovieFrame* frame = (CMovieFrame*)iter.First(); iter.IsNotComplete(); frame = (CMovieFrame*)iter.Next())
  128.         frame->CloseSelection(ev);
  129. }
  130.  
  131. //---------------------------------------------------------------------------------------
  132. //    CMovieSelection::ClearSelection
  133. //---------------------------------------------------------------------------------------
  134.  
  135. FW_Boolean CMovieSelection::ClearSelection(Environment* ev)
  136. {
  137.     FW_CPresentationFrameIterator iter(GetPresentation(ev));
  138.     for (CMovieFrame* frame = (CMovieFrame*)iter.First(); iter.IsNotComplete(); frame = (CMovieFrame*)iter.Next())
  139.         frame->ClearSelection(ev);
  140.  
  141.     return FALSE;
  142. }
  143.  
  144. //---------------------------------------------------------------------------------------
  145. //    CMovieSelection::SelectAll
  146. //---------------------------------------------------------------------------------------
  147.  
  148. void CMovieSelection::SelectAll(Environment* ev)
  149. {
  150.     FW_CPresentationFrameIterator iter(GetPresentation(ev));
  151.     for (CMovieFrame* frame = (CMovieFrame*)iter.First(); iter.IsNotComplete(); frame = (CMovieFrame*)iter.Next())
  152.         frame->SelectAll(ev);
  153. }
  154.  
  155. //---------------------------------------------------------------------------------------
  156. //    CMovieSelection::IsEmpty
  157. //---------------------------------------------------------------------------------------
  158.  
  159. FW_Boolean CMovieSelection::IsEmpty(Environment* ev) const
  160. {
  161.     CMovieFrame* activeFrame = (CMovieFrame*)fMoviePart->GetActiveFrame(ev);
  162.     if (activeFrame)
  163.         return activeFrame->IsSelectionEmpty(ev);
  164.     else
  165.         return TRUE;
  166. }
  167.  
  168. //---------------------------------------------------------------------------------------
  169. //    CMovieSelection::DoExternalizeSelection
  170. //---------------------------------------------------------------------------------------
  171.  
  172. void CMovieSelection::DoExternalizeSelection(Environment* ev, 
  173.                                              ODStorageUnit* destinationSU, 
  174.                                              FW_CCloneInfo* cloneInfo)
  175. {
  176.     FW_UNUSED(cloneInfo);
  177.     
  178.     CMovieFrame* activeFrame = (CMovieFrame*)fMoviePart->GetActiveFrame(ev);
  179.     FW_ASSERT(activeFrame);
  180.     
  181.     CMovie* theMovie = activeFrame->GetMovie(ev);
  182.     
  183.     if (theMovie)
  184.     {
  185.         FW_PlatformHandle movieHandle;
  186.         ODTranslation *translate = fMoviePart->GetSession(ev)->GetTranslation(ev);
  187.         ODType moovType = translate->GetISOTypeFromPlatformType(ev, 'moov', kODPlatformDataType);
  188.         ODType PICTType = translate->GetISOTypeFromPlatformType(ev, 'PICT', kODPlatformDataType);
  189.         
  190.         {
  191.             FW_CStorageUnitSink sink(destinationSU, kODPropContents, fMoviePart->GetPartKind(ev));
  192.             FW_CWritableStream archive(&sink);
  193.             movieHandle = theMovie->CopyCurrentSelectionToHandle();
  194.             FW_CMemoryManager::LockSystemHandle(movieHandle);
  195.             archive.Write(*movieHandle, FW_CMemoryManager::GetSystemHandleSize(movieHandle));
  196.             FW_CMemoryManager::UnlockSystemHandle(movieHandle);
  197.             FW_CMemoryManager::FreeSystemHandle(movieHandle);
  198.         }
  199.         
  200.         {
  201.             //     Add a moov standard type for movies
  202.             //    I have to add it because specific to data interchange (not in AddProperties)
  203.             destinationSU->Focus(ev, kODPropContents, kODPosUndefined, NULL,
  204.                                    (ODValueIndex)0, kODPosUndefined);
  205.             destinationSU->AddValue(ev, moovType);
  206.             FW_CStorageUnitSink sink(destinationSU, kODPropContents, moovType);
  207.             FW_CWritableStream archive(&sink);
  208.             movieHandle = theMovie->CopyCurrentSelectionToHandle();
  209.             FW_CMemoryManager::LockSystemHandle(movieHandle);
  210.             archive.Write(*movieHandle, FW_CMemoryManager::GetSystemHandleSize(movieHandle));
  211.             FW_CMemoryManager::UnlockSystemHandle(movieHandle);
  212.             FW_CMemoryManager::FreeSystemHandle(movieHandle);
  213.         }
  214.  
  215.         {
  216.             //     Add a PICT standard type for parts that don't understand movies
  217.             //    I have to add it because specific to data interchange (not in AddProperties)
  218.             destinationSU->Focus(ev, kODPropContents, kODPosUndefined, NULL,
  219.                                    (ODValueIndex)0, kODPosUndefined);
  220.             destinationSU->AddValue(ev, PICTType);
  221.             FW_CStorageUnitSink sink(destinationSU, kODPropContents, PICTType);
  222.             FW_CWritableStream archive(&sink);
  223.             FW_PlatformPict pictHandle = theMovie->GetAsPict();
  224.             FW_CMemoryManager::LockSystemHandle((FW_PlatformHandle)pictHandle);
  225.             archive.Write(*pictHandle, FW_CMemoryManager::GetSystemHandleSize((FW_PlatformHandle)pictHandle));
  226.             FW_CMemoryManager::UnlockSystemHandle((FW_PlatformHandle)pictHandle);
  227.             ::KillPicture(pictHandle);
  228.         }
  229.     }
  230. }
  231.  
  232. //---------------------------------------------------------------------------------------
  233. //    CMovieSelection::DoInternalizeSelection
  234. //---------------------------------------------------------------------------------------
  235.  
  236. FW_Boolean CMovieSelection::DoInternalizeSelection(Environment* ev, 
  237.                                                     ODStorageUnit* sourceSU, 
  238.                                                     FW_CCloneInfo* cloneInfo)
  239. {
  240.     FW_UNUSED(cloneInfo);
  241.  
  242.     FW_Boolean internalized = FALSE;
  243.     
  244.     ODTranslation *translate = fMoviePart->GetSession(ev)->GetTranslation(ev);
  245.     ODType moovType = translate->GetISOTypeFromPlatformType(ev, 'moov', kODPlatformDataType);
  246.     ODType hfsType = translate->GetISOTypeFromPlatformType(ev, 'hfs ', kODPlatformDataType);
  247.     ODType PICTType = translate->GetISOTypeFromPlatformType(ev, 'PICT', kODPlatformDataType);
  248.  
  249.     ODValueType valueType = fMoviePart->GetPartKind(ev);
  250.     FW_Boolean hasMovieHandle = sourceSU->Exists(ev, kODPropContents, valueType, 0);
  251.     if (!hasMovieHandle)
  252.     {
  253.         valueType = moovType;
  254.         hasMovieHandle = sourceSU->Exists(ev, kODPropContents, valueType, 0);
  255.     }
  256.  
  257.     if (hasMovieHandle)
  258.     {
  259.         FW_CStorageUnitSink sink(sourceSU, kODPropContents, valueType);
  260.         FW_CReadableStream archive(&sink);
  261.         
  262.         unsigned long movieSize = sink.GetReadableBytes();
  263.         FW_PlatformHandle movieHandle = FW_CMemoryManager::AllocateSystemHandle(movieSize);     // THROW_IF_NULL
  264.         FW_ASSERT(movieHandle != NULL);
  265.         
  266.         FW_CMemoryManager::LockSystemHandle(movieHandle);
  267.         archive.Read(*movieHandle, movieSize);
  268.         FW_CMemoryManager::UnlockSystemHandle(movieHandle);
  269.         
  270.         CMovie* newMovie = CMovie::CreateNewMovieFromHandle(movieHandle);
  271.         
  272.         this->PasteMovie(ev, newMovie);
  273.         
  274.         FW_CMemoryManager::FreeSystemHandle(movieHandle);
  275.             
  276.         internalized = TRUE;
  277.     }
  278.     else if (sourceSU->Exists(ev, kODPropContents, hfsType, 0))
  279.     {
  280.         FW_CStorageUnitSink sink(sourceSU, kODPropContents, hfsType);
  281.         FW_CReadableStream archive(&sink);
  282.         
  283.         unsigned long fileSize = sink.GetReadableBytes();
  284.         HFSFlavor* fileData = (HFSFlavor*)FW_CMemoryManager::AllocateBlock(fileSize);
  285.         archive.Read((char*)fileData, fileSize);
  286.         
  287.         FW_CFileSpecification movieSpec(fileData->fileSpec);
  288.         CMovie* newMovie = CMovie::CreateNewMovieFromFile(movieSpec);
  289.         
  290.         this->PasteMovie(ev, newMovie);
  291.         
  292.         FW_CMemoryManager::FreeBlock(fileData);
  293.     }
  294.     else if (sourceSU->Exists(ev, kODPropContents, PICTType, 0))
  295.     {
  296.         FW_CStorageUnitSink sink(sourceSU, kODPropContents, PICTType);
  297.         FW_CReadableStream archive(&sink);
  298.                        
  299.         unsigned long pictSize = sink.GetReadableBytes();
  300.         FW_PlatformPict pictHandle = (FW_PlatformPict)FW_CMemoryManager::AllocateSystemHandle(pictSize);
  301.         FW_ASSERT(pictHandle != NULL);
  302.         
  303.         FW_CMemoryManager::LockSystemHandle((FW_PlatformHandle)pictHandle);
  304.         archive.Read(*pictHandle, pictSize);
  305.         FW_CMemoryManager::UnlockSystemHandle((FW_PlatformHandle)pictHandle);
  306.         
  307.         FW_CPresentationFrameIterator iter(GetPresentation(ev));
  308.         for (CMovieFrame* frame = (CMovieFrame*)iter.First(); iter.IsNotComplete(); frame = (CMovieFrame*)iter.Next())
  309.             frame->PasteHandleToSelection(ev, (FW_PlatformHandle)pictHandle, 'PICT');
  310.             
  311.         ::KillPicture(pictHandle);
  312.  
  313.         internalized = TRUE;
  314.     }
  315.     
  316.     return internalized;
  317. }
  318.  
  319. //---------------------------------------------------------------------------------------
  320. //    CMovieSelection::PasteMovie
  321. //---------------------------------------------------------------------------------------
  322.  
  323. void CMovieSelection::PasteMovie(Environment* ev, CMovie* newMovie)
  324. {
  325.     CMovieFrame* activeFrame = (CMovieFrame*)fMoviePart->GetActiveFrame(ev);
  326.     FW_ASSERT(activeFrame);
  327.     
  328.     if (activeFrame->GetMovie(ev))
  329.     {
  330.         FW_CPresentationFrameIterator iter(GetPresentation(ev));
  331.         for (CMovieFrame* frame = (CMovieFrame*)iter.First(); iter.IsNotComplete(); frame = (CMovieFrame*)iter.Next())
  332.             frame->PasteMovieToSelection(ev, newMovie);
  333.         
  334.         delete newMovie;
  335.     }
  336.     else
  337.     {
  338.         FW_CPresentationFrameIterator iter(GetPresentation(ev));
  339.         for (CMovieFrame* frame = (CMovieFrame*)iter.First(); iter.IsNotComplete(); frame = (CMovieFrame*)iter.Next())
  340.             frame->AdoptNewMovie(ev, newMovie);
  341.     }
  342.     
  343. }
  344.  
  345.